package server;

/**
 * @description: http协议工具类，主要是提供响应头信息，这里我们只提供200和404的情况
 * @author: Archie Wan
 * @time: 2020/12/27 12:47
 */
public class HttpProtocolUtil {
    
    /**
     * 为响应码 200 提供请求头信息
     *
     * @return
     */
    public static String getHttpHeader200(long contentLength) {
        return "HTTP/1.1 200 OK \n" +
                "Content-Type: text/html;charset=utf-8 \n" +
                "Content-Length: " + contentLength + "\n" +
                "\r\n";
    }
    
    /**
     * 为响应码 404 提供请求头信息
     *
     * @return
     */
    public static String getHttpHeader404() {
        String str404 = "<h1>404 Not Found</h1>";
        return "HTTP/1.1 200 OK \n" +
                "Content-Type: text/html;charset=utf-8 \n" +
                "Content-Length: " + str404.getBytes().length + "\n" +
                "\r\n";
    }
    
}
